package AlgorithmHomework.Chapter04;

import Reflection.Introduce.Cat;

import java.util.Scanner;

/**
 * @author 冀玉博
 * @version 1.0
 * 题目：求出从1的阶乘加到n的阶乘
 * 思路：因为要累加，所以使用一个变量去记录一下中间值就行
 */
public class P159_5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入阶乘数：(不要过大，防止溢出)");
        int n =sc.nextInt();
        long ans =1;
        long fn =1;
        if(n==1) System.out.println(1);

        else {
            for (int i = 2; i <= n; i++) {
                fn *= i;
                ans +=fn;
            }
            System.out.println(ans);
        }

    }
}
